package com.liuzh.deviceinfo.card;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import c.h.a.m0.k;
import c.h.a.z.p;

public class PercentCardGroup extends LinearLayout {
    public static final /* synthetic */ int d = 0;
    public PercentCard a;
    public PercentCard b;
    public BroadcastReceiver c = new a();

    public class a extends BroadcastReceiver {
        @SuppressLint({"SetTextI18n"})
        public void onReceive(Context context, Intent intent) {
            int intExtra = intent.getIntExtra("level", -1);
            int intExtra2 = intent.getIntExtra("status", -1);
            int intExtra3 = intent.getIntExtra("voltage", 0);
            int intExtra4 = intent.getIntExtra("temperature", 0) / 10;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(PercentCardGroup.this.getResources().getString(2131690555));
            String str = ": ";
            stringBuilder.append(str);
            stringBuilder.append(intExtra3);
            stringBuilder.append("mV,  ");
            stringBuilder.append(PercentCardGroup.this.getResources().getString(2131690447));
            stringBuilder.append(str);
            stringBuilder.append(intExtra4);
            stringBuilder.append(" ℃");
            PercentCardGroup.this.b.setSummary(stringBuilder.toString());
            if (intExtra2 == 2) {
                PercentCardGroup.this.b.setProgressIndeterminate(true);
            } else {
                PercentCardGroup.this.b.setProgressIndeterminate(false);
            }
            PercentCard percentCard = PercentCardGroup.this.b;
            StringBuilder stringBuilder2 = new StringBuilder();
            stringBuilder2.append(PercentCardGroup.this.getResources().getString(2131689626));
            stringBuilder2.append(" (");
            stringBuilder2.append(k.i(intExtra2, PercentCardGroup.this.getContext()));
            stringBuilder2.append(")");
            percentCard.setTitle(stringBuilder2.toString());
            PercentCardGroup.this.b.setPercent(((float) intExtra) / 100.0f);
        }
    }

    public PercentCardGroup(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        LinearLayout.inflate(getContext(), 2131492930, this);
        this.a = (PercentCard) findViewById(2131296433);
        this.b = (PercentCard) findViewById(2131296425);
        post(new p(this));
    }

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        getContext().registerReceiver(this.c, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
        post(new p(this));
    }

    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.c != null) {
            getContext().unregisterReceiver(this.c);
        }
    }
}
